<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>拖车渠道管理</title>
<jsp:include page="../../import.jsp" flush="true" />
<%--<jsp:include page="assParkCommon.jsp" flush="true" /><!-- 时间格式转换 -->--%>
</head>
<body class="iframeBody">
<div class="Wrapper">
    <div>
        <div class="searchArea">
            <!-- 搜索表单开始 -->
            <form id="searchBar">
                <div class="fieldset1 clearFix">
                    <div class="FXBR">
                        <div class="fieldBox">
                            <div class="label">渠道名称</div>
                            <div class="field">
                                <input type="text" id="channelNm" name="channelNm" class="ui-textbox" ligerui="width: 160" value="">
                            </div>
                        </div>

                        <div class="fieldBox col_33">
                            <div class="label">渠道备案省</div>
                            <div class="field">
                                <select name="recordPrCd" id="recordPrCd">
                                    <option value=" " selected="selected" >请选择</option>
                                    <c:forEach items="${provinceKVList }" var="province">
                                        <option value="${province.key }">${province.value }</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>
                    </div>

                    <div class="clearFix"></div>

                    <!-- 表单按钮 -->
                    <div class="btnsBox formBtns notRight">
                        <span id="searchBtn" class="sq-button-round">查询</span>
                        <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                        <span id="addBtn" class="sq-button-round" onclick="add();">新增渠道</span>
                    </div>
                </div>
            </form>
        </div>
        <!-- 搜索表单结束 -->
        <!-- 列表显示块 -->
        <div id="ligergrid1" class="sq-grid"></div>
    </div>
</div>

<script type="text/javascript">
	var grid = null;
	$(function () {
	    initForm();//初始化表单
	    initGrid();//注意初始化要在initForm之后,因为在初始化grid的时候需要form参数
	    searchBtnEvent();//查询按钮事件
	    clearBtnEvent();//清空按钮事件
	});

	//初始化表单
	function initForm(){
		$("#searchBar").ligerForm();
	}
	
	//查询参数
	function getSearchParams(){
		var form = new liger.get("searchBar");
		var data = form.getData();
		return data;
	}
	
	//初始化列表
	function initGrid(){
		$("#ligergrid1").ligerGrid({
			url:'<%=path%>/ass/assTrailCarChannel/initList.do',
			method:'get',
			parms:getSearchParams(),
			columns:[
                { display: '渠道名称', name: 'channelNm', width: 150, enabledSort:true,
                    render: function (rowdata, rowindex, value, column) {
                        if(StringUtils.isEmpty(value)){
                            value = "";
                        }
                        var h = '';
                        h='<a href="javascript:showDetail(';
                        h+="'"+rowdata.id+"'";
                        h+=",'"+rowdata.channelTypeCd+"'";
                        h+=')">'+value+'</a>'
                        return h;
                    }
                },
				{ display: '渠道类型', name: 'channelTypeCdStr', width: 100, enabledSort:true,},
				{ display: '所属省', name: 'recordPrCdStr', width: 120, enabledSort:true,},
				{ display: '是否启用', name: 'isValid', width: 100, enabledSort:true,
                    render:function (rowdata, rowindex, value){
                        return (value == "1")?"启用中":"禁用";
                    }
                },
                { display: '联系电话', name: 'mp', width: 120, enabledSort:true},
				{ display: '日常所在地', name: 'dailyAddr', width: 120, enabledSort:true},
                { display: '总拖车数', name: 'backQtySum', width: 100, enabledSort:true},
                { display: '总拖车费用(元)', name: 'backAmtSum', width: 120, enabledSort:true},
				getGridOperColumnContent()//操作列
			],
			pageSize:10,
			root:'rows',
			record:'total',
			hideLoadButton:false,
			width:'100%',
			height:'100%',
			heightDiff:-2,
			checkbox:true,//列表是否有选择框
			rownumbers:true//列表是否有行号
		});
		grid = liger.get("ligergrid1");
		grid.setHeight(100);
		grid.options.isSingleCheck = false;//列表是否为单选
	}

	//操作列
    function getGridOperColumnContent(){
		var data = {
			display:'操作',
			isSort:false,
			width:150,
            align:'left',
			render:function (rowdata, rowindex, value){
				var h="";
            	h+='<a class="sq-button-hasicon" alt="修改" href="javascript:modifyRow(';
                h+="'"+rowdata.id+"'";
                h+=")\"><i class=\"sqBtnIco_4\"></i>"+LogUtils.LOG_CMM_GRID_BTN_MODIFY+"</a>";

                var v;
                var v1='<a class="sq-button-hasicon" href="javascript:;" onclick="enable(';
                v1+="'"+rowdata.id+"'";
                v1+=",'"+rowdata.isValid+"'";
                v1+=')"><i class="sqBtnIco_13"></i>'+LogUtils.LOG_CMM_GRID_BTN_DISABLE+'</a>';

                var v2='<a class="sq-button-hasicon" href="javascript:;" onclick="enable(';
                v2+="'"+rowdata.id+"'";
                v2+=",'"+rowdata.isValid+"'";
                v2+=')"><i class="sqBtnIco_12"></i>'+LogUtils.LOG_CMM_GRID_BTN_ENABLE+'</a>';
                switch (rowdata.isValid){
                    case 0:
                        v=v2;
                        break;
                    case 1:
                        v=v1;
                        break;
                    default:
                        v=v1;
                        break;
                }
				return h + v;
			}
		};
		return data;
	}

	//清空按钮事件
	function clearBtnEvent(){
		$("#clearBtn").click(function(event) {
			$("#resetBtn").click();  //重置 input-text
			var form = liger.get("searchBar");
			form.setData({  //重置select等特殊表单
				"vFalg":"",
				"parkStatus":""
			});
		});
	}
	
	//查询按钮事件
	function searchBtnEvent(){
		$("#searchBtn").click(function(event) {
			var form = new liger.get("searchBar");
			var data = form.getData();
			//alert(JSON.stringify(data));
			for (name in data){
				grid.setParm(name,data[name]);
			};
			grid.reload();
		});
	}
	
	//新增
	function add() {
		//回调刷新列表
		var callback = function () {
			grid.reload();
		};
		Add_navTab("Ass_1"+Date.parse(new Date()), "新增拖车渠道信息", '<%=path%>/ass/assTrailCarChannel/toAddPage.do?' , callback);
	}

	//修改信息
	function modifyRow(_id, _validId){
		//回调刷新列表
		/*var callback = function () {
			grid.reload();
		};*/
		if(!_id){
			return;
		}//ID为空不执行
		Add_navTab('Ass_2'+_id,'修改拖车渠道信息','<%=path%>/ass/assTrailCarChannel/toModifyPage.do?id='+_id);
	}
	
	//查看信息
	function showDetail(_id,_cstTypCd){
		//回调刷新列表
		var callback = function () {
			grid.reload();
		};
		if(!_id){
			return;
		}
		Add_navTab('assTrailCarChannel'+_id,'查看拖车渠道信息','<%=path%>/ass/assTrailCarChannel/toDetailPage.do?id='+_id, callback);
	}

    //启用 禁用
    function enable(id, isValid){
        if(!id)return;
        if (isValid == "1") {
            isValid = "0";
            var log = "是否确认禁用?";
        } else {
            isValid = "1";
           var log = "是否确认启用?";
        }
        $.ligerDialog.confirm(log, function (flag) {
            if(flag == false)return;
            $.ajax({
                type: 'post',
                dataType:'json',
                data:{id:id, isValid:isValid},
                url: '<%=path%>/ass/assTrailCarChannel/enable.do',
                success:function(msg){
                    if(msg.success == 1){
                        $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
                        grid.reload();
                    }else{
                        $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
                    }
                }
            });
        });
    }

</script>
</body>
</html>